/*******************************************************************************
*  Project      : Minigate Golfin                                 
*  Program ID   : join_01.js                                 
*  Description  : 회원가입 
*
********************************************************************************
*  Program History                                                            
*  Date        Author    Description                                          
*  ----------  --------  -------------------------------------------------------- 
*  2012-04-16  김효순    Created.  
*  2012-04-16  김효순    Complete.
*******************************************************************************/

jQuery(function($){
	function clsValidate()
	{
		this._init();
	}
	
	clsValidate.prototype = {
		_init: function(){
			var $layer = $("div#container>dl.agree_area");
			
			this._HTMLDom = {
				"$layer": $layer
			}
		}
		, $getLayer: function(){
			return this._HTMLDom["$layer"];
		}
		, isValidate: function(){
			var $layer = this._HTMLDom["$layer"];
			return ($layer.find("input:checkbox:checked").length == $layer.find("input:checkbox").length);
		}
	}
	
	function clsControl()
	{
		this.objValidate = null;
	}
	
	clsControl.prototype = {
		_init: function(){
			this.objValidate = new clsValidate();
			
			this._bind();
		}
		, _bind: function(){
			var thisClass = this;
			
			// 골프인홈
			$("div#top_menu a").attr("id", "idPermissionLink");
			
			// 동의하기, 홈으로
			this.objValidate.$getLayer().on("click", "img[alt='동의하기'], img[alt='홈으로'], img[alt='개인정보취급방침'], img[alt='이용 약관']", function(){
				var bName = $(this).attr("alt");
				
				switch(bName){
					case "동의하기":
						if(thisClass.objValidate.isValidate()){
							thisClass.goJoinPage();
						}else{
							alert("동의합니다에 체크해 주세요.");
						}
						break;
					case "홈으로":
						$("div#top_menu a").get(0).click();
						break;
					case "개인정보취급방침":
						thisClass.goPrivPage();
						break;
					case "이용 약관":
						thisClass.goAgreePage();
						break;
				}
			});
		}
		// 회원가입 이동
		, goJoinPage: function(){
			var szLink = _ROOT + "/member/join_02.html";
			_util.setCookie("join_check", "Y", null, "/");
			
			document.location.href = szLink;
		}
		// 개인정보취급방침 이동
		, goPrivPage: function(){
			var szLink = _ROOT + "/index/privacy.html";
			
			var a = document.createElement("A");
			$(a).attr({
				"href": szLink
				, "id": "idPermissionLink"
				, "target": "_blank"
			});
			$("body").append(a);
			a.click();
			$(a).remove();
		}
		// 이용약관 이동
		, goAgreePage: function(){
			var szLink = _ROOT + "/index/terms.html";
			var a = document.createElement("A");
			$(a).attr({
				"href": szLink
				, "id": "idPermissionLink"
				, "target": "_blank"
			});
			$("body").append(a);
			a.click();
			$(a).remove();
		}
	}
	
	document.objControl = new clsControl();
	document.objControl._init();
});